import { getProfileAPI } from '@/api/Login/user'
import { routes, resetRouter } from '@/router/index'
export default {
  namespaced: true,
  state: () => {
    return {
      permission: [], // 权限标识
      menuList: [] // 路由规则
    }
  },
  mutations: {
    setPermission(state, permission) {
      state.permission = permission
    },
    setMenuList(state, asyncRoutes) {
      state.menuList = [...routes, ...asyncRoutes]
    },
    clearMenuList(state) {
      state.menuList = []
      resetRouter()
    }
  },
  actions: {
    async getPermission(context) {
      const res = await getProfileAPI()
      context.commit('setPermission', res.data.permissions)
      return res.data.permissions
    }
  }
}
